package com.na.report;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.na.report.core.Config;
import com.na.report.db.DBFactory;
import com.na.report.utils.CommonUtils;

public class Application implements ServletContextListener {

	private static Config config;
	private static DBFactory dbFactory;
	
	private static final Logger log = LoggerFactory.getLogger(Application.class);
	
	@Override
	public void contextDestroyed(ServletContextEvent event) {
		log.info("[SERVER SHUTDOWN]OK");
	}

	@Override
	public void contextInitialized(ServletContextEvent event) {
		ServletContext context = event.getServletContext();
		config = CommonUtils.newInstanceByJs(Config.class, "config", context.getResourceAsStream("/WEB-INF/config/config.js"));
		dbFactory = new DBFactory(context.getResourceAsStream("/WEB-INF/config/db_config.xml"));
		log.info("[SERVER INIT]OK");
	}
	
	public static Config getConfig() {
		return config;
	}
	
	public static DBFactory getDBFactory() {
		return dbFactory;
	}

}
